
/*
 数据列表
 */
import schema from './schema.js'
import * as baseOption from '@hp/config/option/echarts/echarts-base.js'
import * as legendOption from '@hp/config/option/echarts/echarts-legend.js'
import * as tooltipOption from '@hp/config/option/echarts/echarts-tooltip.js'
import { useDbSource } from '@hp/hooks/useDbSource.js'

const { loadDataCols } = useDbSource()

export default {
  // 组件
  component: () => import("./ChartBar.vue"),
  // 类型
  type: 'chartbar',
  // 名称
  name: '柱状图',
  // 图标或图片
  icon: 'pi/chart-bar.png',
  // 初始配置
  schema,
  // 大小定位
  layout: {
    i: '',
    x: '',
    y: '',
    w: 60,
    h: 35,
    minW: 24,
    minH: 12,
    maxW: 120,
    // maxH: 35,
    static: false,
  },
  // 配置
  config: [
    {
      config: {
        label: '基础配置'
      },
      children: [
        {
          type: 'switch',
          field: 'echarts.isX',
          label: '横向',
          compProps: {
            defaultValue: false
          }
        },
      ]
    },
    {
      config: {
        label: '数据配置'
      },
      children: [
        // {
        //   type: 'input-cards',
        //   field: 'dataList',
        //   label: '数据集',
        //   noForm: true,
        //   compProps: {
        //     // 必须存在
        //     mustHas: true,
        //     // 是否显示添加
        //     showAdd: false,
        //   },
        //   children: [
        //     {
        //       type: "input-dbsource",
        //       label: "数据源",
        //       field: "dataList.dataSource",
        //       compProps: {
        //       }
        //     },
        //     {
        //       type: "input",
        //       label: "名称",
        //       field: "dataList.name",
        //       compProps: {
        //         getUpConfig({ schema }) {
        //           return {
        //             display: schema.dataList.length > 1
        //           }
        //         }
        //       }
        //     },
        //     {
        //       type: "select",
        //       label: "维度",
        //       field: "dataList.labelKey",
        //       compProps: {
        //         labelTooltip: '需要展示数据的类型',
        //         getUpConfig({ row }) {
        //           return {
        //             options: loadDataCols(row)
        //           }
        //         }
        //       }
        //     },
        //     {
        //       type: "series-line",
        //       label: "指标",
        //       field: "dataList.valueKeys",
        //       noForm: false,
        //       compProps: {
        //         defaultValue: [],
        //         type: 'bar',
        //         configData: {
        //           name: '',
        //           field: '',
        //           color: '',
        //           barWidth: '',
        //           stack: false,
        //           label: false,
        //           labelColor: '',
        //           labelPosition: 'top',
        //         }
        //       },
        //       children: [
        //       ]
        //     },
        //   ]
        // },
        {
          type: "input-dbsource",
          label: "数据源",
          field: "dataSource",
          compProps: {
          }
        },
        {
          type: "select",
          label: "维度",
          field: "labelKey",
          compProps: {
            getUpConfig ({ schema, row }) {
              return {
                options: loadDataCols(row)
              }
            }
          }
        },
        {
          type: "series-line",
          label: "指标",
          field: "valueKeys",
          noForm: false,
          compProps: {
            type: 'bar',
            defaultValue: [],
            configData: {
              name: '',
              field: '',
              color: '',
              barWidth: '',
              stack: false,
              label: false,
              labelColor: '',
              labelPosition: 'top',
            }
          },
          children: [
            {
              type: "name",
              label: "名称",
              field: "dataList.valueKeys.name",
              compProps: {
              }
            },
            {
              type: "field",
              label: "字段",
              field: "dataList.valueKeys.name",
              compProps: {
              }
            },
          ]
        },
      ]
    },
    {
      config: {
        label: 'X轴配置'
      },
      children: [
        {
          type: 'input',
          field: 'echarts.xAxis.name',
          label: '名称',
          compProps: {
          }
        },
        {
          type: 'select',
          field: 'echarts.xAxis.nameLocation',
          label: '名称位置',
          compProps: {
            options: baseOption.AxisNameLocationOptions
          }
        },
        {
          type: 'select',
          field: 'echarts.xAxis.position',
          label: '轴位置',
          compProps: {
            defaultValue: "bottom",
            options: [{
              value: "bottom",
              label: "下"
            }, {
              value: "top",
              label: "上"
            }]
          }
        },
        {
          type: 'select',
          field: 'echarts.xAxis.type',
          label: '数值类型',
          compProps: {
            options: baseOption.AxisTypeOptions
          }
        },
        {
          type: 'switch',
          field: 'echarts.xAxis.axisTick.alignWithLabel',
          label: '刻度线对齐',
          compProps: {
            defaultValue: false
          }
        },
        {
          type: 'switch',
          field: 'echarts.xAxis.boundaryGap',
          label: '坐标轴留白',
          compProps: {
            defaultValue: true
          }
        }
      ]
    },
    {
      config: {
        label: 'Y轴配置'
      },
      children: [
        {
          type: 'input',
          field: 'echarts.yAxis.name',
          label: '名称',
          compProps: {
          }
        },
        {
          type: 'select',
          field: 'echarts.yAxis.nameLocation',
          label: '名称位置',
          compProps: {
            options: baseOption.AxisNameLocationOptions
          }
        },
        {
          type: 'select',
          field: 'echarts.yAxis.type',
          label: '数值类型',
          compProps: {
            options: baseOption.AxisTypeOptions
          }
        },
        {
          type: 'switch',
          field: 'echarts.yAxis.axisTick.alignWithLabel',
          label: '刻度线对齐',
          compProps: {
            defaultValue: false
          }
        }
      ]
    },

    {
      config: {
        label: '图例设置'
      },
      children: [
        {
          type: 'switch',
          field: 'echarts.legend.show',
          label: '是否显示',
          compProps: {
          }
        },
        {
          type: 'select',
          field: 'echarts.legend.orient',
          label: '布局朝向',
          compProps: {
            options: legendOption.LegendOrientOptions
          }
        },
        {
          type: 'select',
          field: 'echarts.legend.align',
          label: '所在位置',
          compProps: {
            options: legendOption.LegendAlignOptions
          }
        },
      ]
    },
    {
      config: {
        label: '网格设置'
      },
      children: [
        {
          type: 'switch',
          field: 'echarts.grid.containLabel',
          label: '包含坐标',
          compProps: {
            defaultValue: true
          }
        },
        {
          type: 'slider',
          field: 'echarts.grid.left',
          label: '左边距',
          compProps: {
            defaultValue: 10
          }
        },
        {
          type: 'slider',
          field: 'echarts.grid.right',
          label: '右边距',
          compProps: {
            defaultValue: 10
          }
        },
        {
          type: 'slider',
          field: 'echarts.grid.top',
          label: '上边距',
          compProps: {
            defaultValue: 10
          }
        },
        {
          type: 'slider',
          field: 'echarts.grid.bottom',
          label: '下边距',
          compProps: {
            defaultValue: 10
          }
        },
      ]
    },
    {
      config: {
        label: '提示框设置'
      },
      children: [
        {
          type: 'select',
          field: 'echarts.tooltip.axisPointer.type',
          label: '类型',
          compProps: {
            options: tooltipOption.AxisPointerTypeOptions
          }
        },
        {
          type: 'select',
          field: 'echarts.tooltip.trigger',
          label: '触发类型',
          compProps: {
            options: tooltipOption.TooltipTriggerOptions
          }
        },
      ]
    },
    {
      config: {
        label: '事件配置'
      },
      children: [
        {
          type: 'event-onclick',
          field: 'onClick',
          label: 'onClick',
          compProps: {
          }
        },
      ]
    }
  ]
}